//
//  Select_scopeViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/17.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Select_scopeViewController.h"

#import "Select_scopeTableViewCell.h"

@interface Select_scopeViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation Select_scopeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"选择范围";
    
    //取消
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(15, 35, 50, 15)];
    lbl_return.text = @"取消";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(13, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右确定
    UIButton * btn_Edit = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_Edit.frame = CGRectMake(SCREEN_WIDTH - 5 - 50, 20 + 7, 50, 30);
    [btn_Edit setTitle:@"确定" forState:(UIControlStateNormal)];
    [btn_Edit setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_Edit.titleLabel.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:btn_Edit];
    [btn_Edit addTarget:self action:@selector(btn_EditAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左取消
- (void )btn_returnAction:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

//右确定
- (void )btn_EditAction:(UIButton *)sender
{
//    NSLog(@"保存并提交服务器");
    
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

//tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Select_scopeTableViewCell class] forCellReuseIdentifier:@"Select_Scope"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0f;
}

- (UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Select_scopeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Select_Scope" forIndexPath:indexPath];
    
    if(indexPath.section == 0)
    {//部门
        cell.image_department.image = [UIImage imageNamed:@"Department.png"];
        cell.name_department.text = @"销售中心";
        cell.department_number.text = @"17人";
        cell.btn_delete.tag = indexPath.row;
    }
    else
    {//同事
        cell.image_department.image = [UIImage imageNamed:@"heads.jpg"];
        cell.name_department.text = @"XXX";
        cell.department_number.text = @"销售经理-销售部";
        cell.btn_delete.tag = 1000 + indexPath.row;
    }
    
    [cell.btn_delete addTarget:self action:@selector(btn_deleteAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

//左边的
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if(section == 0)
    {
        return @"部门";
    }
    else
    {
        return @"同事";
    }
}

#pragma mark - 点击删除选中行
- (void )btn_deleteAction:(UIButton *)sender
{//NSLog(@"点击删除选中行");
    
    if(sender.tag > 500)
    {
        NSLog(@"同事");
    }
    else
    {
        NSLog(@"部门");
    }
}



















@end
